package com.tmxk.days01.demo3_pets_wmh;

public class RabbitTest {
    public static void main(String[] args){
        //实例化Rabbit对象
        Rabbit rabbit = new Rabbit("长毛兔", 3, "兔子", "腿短,耳朵长");
        // 父类强制子类必须实现的叫方法
        rabbit.shout();
        // 兔子子类特有的方法
        rabbit.run();
        // 输出兔子实例对象
        System.out.println(rabbit);

        /**
         * 需求: 比较两个相同数据兔子实例是否相等
         */
        Rabbit rabbit1 = new Rabbit("长毛兔1", 3, "兔子", "腿短,耳朵长");
        Rabbit rabbit2 = new Rabbit("长毛兔1", 3, "兔子", "腿短,耳朵长");

        Rabbit rabbit11 = new Rabbit("长毛兔1");
        Rabbit rabbit22 = new Rabbit("长毛兔1");


        String str1 = "长毛兔1";    // String类型直接定义的字符串是存储在  堆中的(字符串)常量池中
        String str2 = "长毛兔1";

        // 多态的体现
        Object rabbitStr1 = new String("长毛兔1");
        Object rabbitStr2 = new String("长毛兔1");


        // == : 比较的是内存地址     equals 比较的是数据值
        System.out.println("str1 == str2 :" + (str1 == str2));      		// true
        System.out.println("str1.equals(str2) :" + (str1.equals(str2)));    // true

        System.out.println(" rabbitStr1 == rabbitStr2: " + (rabbitStr1 == rabbitStr2));  // false
        System.out.println(" rabbitStr1.equals(rabbitStr2): " + (rabbitStr1.equals(rabbitStr2))); // true


        System.out.println(" Rabbit rabbit11 == Rabbit rabbit22: " + (rabbit11 == rabbit22));  // false
        System.out.println(" rabbit11.equals(rabbit22): " + (rabbit1.equals(rabbit2))); // false

    }
}
